import requests,json
import base64
# 密钥
TOKEN = "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"

# API_URL = "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-xl-base-1.0"
API_URL = "https://api-inference.huggingface.co/models/runwayml/stable-diffusion-v1-5"
# API_URL = "https://api-inference.huggingface.co/models/williamberman/stable-diffusion-v1-5-controlnet-canny-full-no-ema"
headers = {"Authorization": "Bearer " + TOKEN} # 自己的密钥


def query(payload):
	response = requests.post(API_URL, headers=headers, json=payload)
	return response.content

# data = {
#     "input" : "a women swimming in the pool"
# }
data = {
    "prompt": "a women swimming in the pool",
    "negative_prompt": None,
    "width": "512",
    "height": "512",
    "samples": "1",
    "num_inference_steps": "20",
    "safety_checker": "no",
    "enhance_prompt": "yes",
    "seed": None,
    "guidance_scale": 7.5,
    "multi_lingual": "no",
    "panorama": "no",
    "self_attention": "no",
    "upscale": "no",
    "embeddings_model": None,
    "webhook": None,
    "track_id": None
    }
image_binary = query(json.dumps(data))

print(image_binary)

with open("C:\\Users\\SA\\Desktop\\3.jpg", 'wb') as f:
    f.write(image_binary)
